package com.powernode.until;


import org.springframework.util.StringUtils;

import java.util.Random;

public class PhoneCodeUntil {

    /**
     * 生成指定位数的验证码
     *
     * @param resource
     * @param size
     * @return
     */
    public static String phoneCodeUntil(String resource, int size) {

        if (!StringUtils.hasText(resource)) {
            resource = "0123456789";
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < size; i++) {
            int index = new Random().nextInt();
            sb.append(resource.charAt(index));
        }
        return sb.toString();
    }


    /**
     * 生成指定位
     *
     * @param size
     * @return
     */
    public static String phoneCodeUntil(int size) {
        return PhoneCodeUntil.phoneCodeUntil(null, size);
    }
}
